import 'dart:convert';

import 'package:flutter_test/flutter_test.dart';
import 'package:im_app/im/socket/dto/business/WebRtcData.dart';
import 'package:im_app/im/util/LoggerUtil.dart';
import 'package:im_app/im/webrtc/dto.dart';

void main() {
  var _logger = createLogger();

  test("jsonWebRtc", () async {
    var candidateReq = WebRtcP2pCandidateReq(roomName: 'demo', toUserId: 'test00100',
        iceCandidate: IceCandidate(sdpMid: '11', sdpMLineIndex: 0, candidate: 'candidate'));
    var json = jsonEncode(candidateReq);
    _logger.i("WebRtcP2pCandidateReq json:  $json");
    var req = jsonDecode(json);
    var json2 = jsonEncode(req);
    _logger.i("WebRtcP2pCandidateReq2 json:  $json2");
    assert(json==json2);
  });

  test("jsonWebRtcP2pSdpReqTest", () async {
    var sdpReq = WebRtcP2pSdpReq(roomName: 'demo', toUserId: 'test00100',
        sdpType: SdpType.offer, sdp: '3232');
    var jsonMap = sdpReq.toJson();
    var json = jsonEncode(sdpReq);
    _logger.i("WebRtcP2pSdpReq json:  $json");
    var req = jsonDecode(json);
    var json2 = jsonEncode(req);
    _logger.i("WebRtcP2pSdpReq2 json:  $json2");
    assert(json==json2);
  });

  test("jsonWebRtcInvitationReqTest", () async {
    var userIds = Set<String>();
    userIds.add('test001');

    ChatType.audio;
    var invitationReq = WebRtcInvitationReq(roomName: 'demo', fromUserId: 'test00100',
        chatType: ChatType.video, userIds: userIds);
    var map = invitationReq.toJson();
    var json = jsonEncode(map);
    _logger.i("WebRtcInvitationReq json:  $json");
    var req = jsonDecode(json);
    var json2 = jsonEncode(req);
    _logger.i("WebRtcInvitationReq2 json:  $json2");
    assert(json==json2);
  });
}